#!/bin/csh -f

set bluntcopy=0
if ( "$1" == "--copy" ) then
	set bluntcopy=1
	shift
endif

if ( $bluntcopy == 0 ) then
    if ( ! -e "$1" ) then
	echo "$0 uses meld with the corresponding one from od or dgb"
	exit 1
    endif
endif


foreach fnm ( $* )

    set dirnm=`pwd`

    set modnm=$dirnm:t
    set srcincpth=$dirnm:h
    set srcinc=$srcincpth:t
    set reldirpth=$srcincpth:h
    set reldir=$reldirpth:t
    set wrkdir=`echo $reldir|sed 's/[456].*$//'`
    set goback="../../.."
    if ( $wrkdir != "dgb" && $wrkdir != "od" ) then
	    set srcinc=plugins/$wrkdir/$srcinc
	    set reldirpth=$reldirpth:h:h
	    set reldir=$reldirpth:t
	    set wrkdir=`echo $reldir|sed 's/[456].*$//'`
	    set goback="../../../../.."
    endif

    if ( $bluntcopy == 0 ) then
	    echo "meld $fnm $goback/$wrkdir/$srcinc/$modnm/$fnm"
	    meld $fnm $goback/$wrkdir/$srcinc/$modnm/$fnm
    else
	    echo "cp $goback/$wrkdir/$srcinc/$modnm/$fnm ."
	    cp $goback/$wrkdir/$srcinc/$modnm/$fnm .
endif

end

